package com.leetcode.two_pointers.sliding_window;

/**
 * @author Dennis Li
 * @date 2020/9/16 16:15
 */
public class CharacterReplacement_424 {


    public int characterReplacement(String s, int k) {
        if (s == null) return 0;
        int[] hash = new int[26];
        int left = 0, historyCharMax = 0;
        char[] array = s.toCharArray();
        for (int right = 0; right < array.length; right++) {
            int index = array[right] - 'A';
            hash[index]++;
            historyCharMax = Math.max(historyCharMax, hash[index]);
            if (right - left + 1 > historyCharMax + k) {
                hash[array[left] - 'A']--;
                left++;
            }
        }
        return array.length - left;
    }

}
